package ua.flatmap.processor.realt;

import org.apache.commons.io.FileUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.webharvest.definition.ScraperConfiguration;
import org.webharvest.runtime.Scraper;
import org.webharvest.runtime.variables.Variable;
import ua.flatmap.processor.Scrapper;
import ua.flatmap.processor.XMLReader;

import java.io.FileNotFoundException;

/**
 * Created by IntelliJ IDEA.
 * User: Kostya
 * Date: 14.07.11
 */
public class RealtScrapper implements Scrapper {
    public void execute() {
        ApplicationContext context = new ClassPathXmlApplicationContext("/spring/scanner-ctx.xml");
        String tempDir = FileUtils.getTempDirectoryPath() + "\\" + System.currentTimeMillis();
        ScraperConfiguration config = null;
        try {
            config = new ScraperConfiguration("flatsmap-scanner\\src\\main\\resources\\webharvest\\realt.xml");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        Scraper scraper = new Scraper(config, tempDir);

        scraper.addVariableToContext("realt_url", "http://realt.ua/Db2/0Sd_Kv.php?cnt_all=933&Obl=10&nDay=5&TmSdch=9999&showNum=5&srtby=5&pos=0");
        scraper.execute();
        Variable result = (Variable) scraper.getContext().get("result");
        XMLReader reader = (XMLReader) context.getBean("realtXmlReader");
        reader.execute(result.toString());

    }
}
